﻿using System;
using System.Text;
using System.Xml.Serialization;
using System.Globalization;

namespace QuickDev.Licensing
{
    public class WebServiceLicense : License , ILicense
    {
        private string _domain;
        private DateTime _expirationDate;
        private string _key;
        private string _product;
        private string _type;
        private string _user;

        public override string Domain
        {
            get
            {
                return this._domain;
            }
            set
            {
                this._domain = value;
            }
        }

        public override DateTime ExpirationDate
        {
            get
            {
                return this._expirationDate;
            }
            set
            {
                this._expirationDate = value;
            }
        }

        public override string Key
        {
            get
            {
                return this._key;
            }
            set
            {
                this._key = value;
            }
        }

        public string Product
        {
            get
            {
                return this._product;
            }
            set
            {
                this._product = value;
            }
        }

        [XmlIgnore]
        public override byte[] Signature
        {
            get
            {
                StringBuilder builder = new StringBuilder();
                builder.Append( this.User );
                builder.Append( this.Type );
                builder.Append( this.Product );
                builder.Append( this.Domain );
                builder.Append( this.ExpirationDate.ToString( CultureInfo.CreateSpecificCulture( "en-US" ) ) );
                return Encoding.UTF8.GetBytes( builder.ToString() );
            }
        }

        public override string Type
        {
            get
            {
                return this._type;
            }
            set
            {
                this._type = value;
            }
        }

        public string User
        {
            get
            {
                return this._user;
            }
            set
            {
                this._user = value;
            }
        }
    }
}